package practice;
/*题目：有一分数序列：2/1，3/2，5/3，8/5，13/8，21/13...求出这个数列的前20项之和。
        程序分析：请抓住分子与分母的变化规律。*/
public class practice20 {

    public static void main(String[] args) {
        int sum = 0;
        int[] fz = new int[20];
        int[] fm = new int[20];

        for (int i = 0; i < 20; i++) {
            if(i == 0) {
                fz[i] = 2;
                fm[i] = 1;
            }else if (i < 2) {
                fz[i] = fz[i - 1] + 1;
                fm[i] = fm[i - 1] + 1;
            }else {
                fz[i] = fz[i - 2] + fz[i - 1];
                fm[i] = fm[i - 2] + fm[i - 1];
            }
            sum += fz[i] / fm[i];
//            System.out.println(sum + "\t" + fz[i] + "\t" + fm[i]);
        }
        System.out.println("sum = " + sum);
    }

}
